<template>
  <div>
    <div>
      <FormPanel ref="formPanel" :list="fromList" :cols="1" labelWidth="130" :isSubmitBtn="false"></FormPanel>
    </div>

    <div :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }">
      <AjaxButton type="primary" :disabled="newStatus" :click="saveDialog">保 存</AjaxButton>
      <!-- <AjaxButton type="primary" :disabled="submitEnable" :click="submit">提 报</AjaxButton> -->
      <el-button @click="closeDialog">关 闭</el-button>
    </div>
  </div>
</template>

<script>
import { getConfigHeaders } from '@/api/fetch';
import { jsonToHump } from '@/utils/index';
import { dictionary } from '@/utils/dictMixin';
import { editLevel } from '@/api/claim/dealer/AuthMaintenance';
export default {
  props: ['row', 'type'],
  mixins: [dictionary],
  data() {
    return {
      fromList: this.createFromList(),
      modelId: undefined,
      isShowGdcx: false,
      fileList: [],
      getConfigHeaders: getConfigHeaders,
      ownerNo: '',
      newStatus: false
    };
  },
  computed: {
    submitEnable() {
      return !!!this.fromList.find(x => x.fieldName === 'changeNo').initialValue;
    }
  },
  mounted() {
    this.fromList.forEach(x => {
      x.initialValue = this.row[x.fieldName];
    });
  },
  methods: {
    createFromList() {
      return [
        {
          type: 'INPUT',
          label: '预授权级别编号',
          fieldName: 'code',
          disabled: this.type == 'edit',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '预授权级别编号名称',
          fieldName: 'name',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '预授权类型',
          fieldName: 'authType',
          itemList: this.createDictList('5508'),
          rules: [{ required: true, message: '请选择', trigger: 'blur' }],
          initialValue: ''
        }
      ];
    },
    async saveDialog() {
      const [err, data] = await this.$refs.formPanel.GET_FORM_DATA();
      if (err) return;
       console.log(data)
      data.id = this.row.id;
      let res = await editLevel(data);
      if (res.resultCode === 200) {
        this.$notify.success({ type: '提示信息', message: '保存成功!!' });
        this.newStatus = true;
        this.$emit('close');
      } else {
        this.$notify.success({ type: '提示信息', message: res.errMsg });
        this.newStatus = true;
        this.$emit('close');
      }
    },
    submit() {
      this.saveDialog('submit'); //
    },
    closeDialog() {
      this.$emit('close');
    }
  }
};
</script>
